package com.zyz.system.controller.exam;

import com.zyz.common.core.model.Result;
import com.zyz.common.core.model.TableDataInfo;
import com.zyz.system.model.exam.dto.ExamAddDTO;
import com.zyz.system.model.exam.dto.ExamEditDTO;
import com.zyz.system.model.exam.dto.ExamQueryDTO;
import com.zyz.system.model.exam.dto.ExamQuestionAddDTO;
import com.zyz.system.model.exam.vo.ExamDetailVO;
import com.zyz.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/exam")
@RestController
@Tag(name = "竞赛接口")
public class ExamController {


    @Autowired
    private IExamService examService;

    @Operation(summary = "获取竞赛列表")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public TableDataInfo list (ExamQueryDTO examDTO) {
        return examService.list(examDTO);
    }


    @Operation(summary = "新增竞赛")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<String> add (@RequestBody ExamAddDTO examAddDTO) {
        return Result.ok(examService.add(examAddDTO).toString());
    }

    @Operation(summary = "竞赛题目添加")
    @RequestMapping(value = "/question/add",method = RequestMethod.POST)
    public Result<Void> questionAdd(@RequestBody ExamQuestionAddDTO examQuestionAddDTO) {
        examService.questionAdd(examQuestionAddDTO);
        return Result.ok();
    }

    @Operation(summary = "竞赛题目删除")
    @RequestMapping(value = "/question/delete",method = RequestMethod.DELETE)
    public Result<Void> questionDelete(Long examId, Long questionId) {
        examService.questionDelete(examId,questionId);
        return Result.ok();
    }

    @Operation(summary = "根据竞赛id获取竞赛详情")
    @RequestMapping(value = "/detail",method = RequestMethod.GET)
    public Result<ExamDetailVO> detail (Long examId) {
        return Result.ok(examService.detail(examId));
    }

    @Operation(summary = "竞赛修改")
    @RequestMapping(value = "/edit",method = RequestMethod.PUT)
    public Result<Void> edit (@RequestBody ExamEditDTO examEditDTO) {
        examService.edit(examEditDTO);
        return Result.ok();
    }

    @Operation(summary = "删除竞赛")
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public Result<Void> delete(Long examId) {
        examService.delete(examId);
        return Result.ok();
    }

    @Operation(summary = "发布竞赛")
    @RequestMapping(value = "/publish",method = RequestMethod.PUT)
    public Result<Void> publish (Long examId) {
        examService.publish(examId);
        return Result.ok();
    }

    @Operation(summary = "取消发布竞赛")
    @RequestMapping(value = "/cancelPublish",method = RequestMethod.PUT)
    public Result<Void> cancelPublish (Long examId) {
        examService.cancelPublish(examId);
        return Result.ok();
    }
}
